﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeakReferenceDemo;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create the cache.
            int cacheSize = 50;
          
            Random r = new Random();
            Cache c = new Cache(cacheSize);
            GC.Collect(0);//把CACHE里的弱引用都回收了
            string DataName = "";
            
           

            // Randomly access objects in the cache.
            for (int i = 0; i < c.Count; i++)
            {
                int index = r.Next(c.Count);

                // Access the object by getting a property value.
                DataName = c[index].Name;
            }
            // Show results.
            double regenPercent = c.RegenerationCount / (double)c.Count;
            Console.WriteLine("Cache size: {0}, Regenerated: {1:P2}%", c.Count, regenPercent);
            Console.ReadLine();
        }
    }
}
